//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.IO;
using OpenLS.Spreadsheet.Expressions;

namespace OpenLS.Spreadsheet.Formats.Biff.Tokens
{
    internal class RefError3DToken : FormulaToken
    {
        private readonly AccessorType _type;
        private ushort sheetId;
        private uint notUsed;

        public RefError3DToken(AccessorType type)
        {
            _type = type;
        }

        public override ushort GetLength(FormulaReadContextType formulaReadContextType)
        {
            return 6;
        }

        internal override void ReadContent(FormulaReadContext context)
        {
            this.sheetId = context.ReadUInt16();
            this.notUsed = context.ReadUInt32();
        }
        public override void WriteContent(FormulaWriteContext context)
        {
            context.WriteUInt16(sheetId);
            context.WriteUInt32(notUsed);
        }

        public override FormulaTokenId TokenId
        {
            get {
                switch (_type)
                {
                        case AccessorType.Array:
                        return FormulaTokenId.RefErr3dA;
                        case AccessorType.Reference:
                        return FormulaTokenId.RefErr3d;
                        case AccessorType.Value:
                        return FormulaTokenId.RefErr3dV;
                    default:
                        throw new NotSupportedException();
                } }
        }

        internal override Expression GetExpression(FormulaEvaluationContext context)
        {
            return new ErrorExpression(Errors.RefError);
        }
    }
}